//Function for Pattern entry

#include "easybutterfly.h"
#include "macro.h"

int pattern()
{	
	int patt = 1;										//Pattern's authenticity
	int cntr = 1;										//'cntr'th character entered
	while(patt)
	{	
		LCD_TEXT("-- ENTER CODE --")
		switch(cntr)
		{
			case 1:
			if(btn_left)
			{
				while(btn_left);
				cntr = 2;
			}
			else if(btn_right || btn_down || btn_up)	//Incorrect entry
			{
					cntr = 5;
			}
			else
			{
			}
			break;
			
			case 2:
			if(btn_down)
			{
				while(btn_down);
				cntr = 3;
			}
			else if(btn_right || btn_left || btn_up)	//Incorrect entry
			{
				cntr = 5;
			}
			else
			{
			}
			break;
			
			case 3:
			if(btn_right)
			{
				while(btn_right);
				cntr = 4;
			}
			else if(btn_down || btn_left || btn_up)		//Incorrect entry
			{
			cntr = 5;
			}
			else
			{
			}
			break;
			
			case 4:
			if(btn_up)
			{
				while(btn_up);
				return patt;
			}
			else if(btn_down || btn_left || btn_up)		//Incorrect entry
			{
				cntr = 5;
			}
			break;
			
			case 5:
			//Case where the pattern entered is incorrect
			patt = 0;
			return patt;
			break;
				
			default:
				break;
		}
	}
}